package com.dmgameclient.fragments;

import java.util.concurrent.Executors;

import com.dmgameclient.R;
import com.dmgameclient.common.URLHelper;
import com.dmgameclient.widget.CustomDialog;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;

/**
 * @name ContentFragment2
 * @Descripation <br>
 *               1、<br>
 *               2、<br>
 * @author 樊俊彬
 * @date 2014-9-20
 * @version 1.0
 */
public class FragmentForum extends Fragment {

	private static final String TAG = "FragmentForum";
	private WebView forunWebView;
	private CustomDialog dialog;
	private Handler handler;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_forum_content,
				container, false);
		dialog = new CustomDialog(getActivity());
		forunWebView = (WebView) view.findViewById(R.id.forunWebView);
		WebSettings settings = forunWebView.getSettings();
		settings.setUseWideViewPort(true);
		settings.setLoadWithOverviewMode(true);
		forunWebView.loadUrl(URLHelper.FORUM_URL);
		initFrame();
		loadData();
		return view;
	}

	private void initFrame() {
		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				dialog.dismiss();
			}
		};
	}

	private void loadData() {
		Executors.newSingleThreadExecutor().execute(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				try {
					Thread.sleep(800);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				handler.sendEmptyMessage(0);
			}
		});
	}

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}
}
